#include <QtGui/QApplication>
#include <QDeclarativeContext>
#include <QtDeclarative>
#include <QtCore/QtGlobal>
#include <QTranslator>
#include <QDebug>
#include <QFile>
#include <QTextCodec>
#include "qmlapplicationviewer.h"
#include "rengine.h"
#include "rbookmark.h"
#include "rconstdifinition.h"

QString translationFileName() {
    QString language;
    switch (QLocale::system().language()) {
        case QLocale::Chinese:
            language = KI18NLangCN;
            break;

        default:
            language = KI18nLangEN;
    }

    return KI18NFilePath+KI18NFilePrefix+language+KI18NFileSuffix;
}

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QApplication *app = createApplication(argc, argv);

//    QTextCodec::setCodecForCStrings(QTextCodec::codecForName(KCodecUTF8.toLatin1()));

    QTranslator qtTranslator;
    qDebug()<<translationFileName()<<QFile::exists(translationFileName());
    if (qtTranslator.load(translationFileName())) {
        app->installTranslator(&qtTranslator);
    }

    qmlRegisterType<REngine>("REngine", 1, 0, "REngine");
    qmlRegisterType<RBookmark>("RBookmark", 1, 0, "RBookmark");

    QmlApplicationViewer *viewer = QmlApplicationViewer::create();
    REngine* engine = new REngine;
    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->rootContext()->setContextProperty("engine", engine);
    viewer->setMainQmlFile(QLatin1String("qml/main.qml"));
    viewer->showExpanded();

    return app->exec();
}
